package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.DoGood;
import cn.wolfcode.trip.base.query.DoGoodQueryObject;
import cn.wolfcode.trip.base.service.*;
import cn.wolfcode.trip.base.util.JSONResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 点赞的资源控制器
 */
@RestController
@RequestMapping("dogood")
public class DoGoodController {
    @Autowired
    private IDoGoodService doGoodService;
    @Autowired
    private IStrategyService strategyService;
    @Autowired
    private ITravelService travelService;
    @Autowired
    private INewsPageService newsPageService;

    /**
     * 新增/删除
     *
     * @param doGood
     * @return
     */
    @GetMapping
    public JSONResult doGood(DoGood doGood) {
        JSONResult result = new JSONResult();

        DoGood con = doGoodService.selectOne(doGood);
        if (con == null) {
            doGoodService.saveOne(doGood);
        } else {
            doGoodService.deleteOne(doGood);
            result.setSuccess(false);
        }
        return result;
    }

    /**
     * 查询是否有该条点赞
     *
     * @param doGood
     * @return
     */
    @GetMapping("select")
    public JSONResult select(DoGood doGood) {
        JSONResult result = new JSONResult();
        DoGood con = doGoodService.selectOne(doGood);
        if (con == null) {
            result.setSuccess(false);
        }
        return result;
    }

    /**
     * 计数
     *
     * @param doGood
     * @return
     */
    @GetMapping("count")
    public Map selectForCount(DoGood doGood) {
        HashMap<String, Object> map = new HashMap<>();
        int count = doGoodService.selectForCount(doGood);
        map.put("count", count);
        return map;
    }

    /**
     * 查询用户点赞的攻略/游记/日报
     *
     * @param qo
     * @return
     */
    @GetMapping("list/count")
    public PageInfo listForCount(DoGoodQueryObject qo) {
        /*if(qo.getType() == 1){
            PageInfo pageInfo = strategyService.selectForDoGood(qo);
            return pageInfo;
        } else if(qo.getType() == 2){
            return travelService.selectForDoGood(qo);
        } else if(qo.getType() == 3){
            return newsPageService.selectForDoGood(qo);
        }*/
        return null;
    }
}
